package com.ruipengkj.view.memberView;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;

public class MemberCouponFrame extends BaseInternalFrame{

	private static final long serialVersionUID = 1L;
	
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	

	private JButton queryCardButton;//优惠卷查询按钮
	private MemberCoupon meberQueryCardPanel;//优惠卷查询面板
	
//	private JButton queryCardAddButton;//优惠卷查询按钮
//	private MemberCreateCashCardPanel meberAddCardPanel;//优惠卷查询面板

	public MemberCouponFrame(String title, boolean resizable, boolean closable, boolean maximizable,boolean iconifiable){
		super(title, resizable, closable, maximizable,iconifiable);
		this.init();
	}
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.initViews();
		this.initListener();
	}
	
	//初始化组件
	private void initViews(){
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		
		queryCardButton=new JButton("优惠卷查询",SwingUtil.getOpenSwingImage("member_ card_query.png"));
//		queryCardAddButton=new JButton("添加优惠卷",SwingUtil.getOpenSwingImage("member_ card_query.png"));

		
		
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL91)){
			toolBar.add(queryCardButton);
		}
//		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL92)){
//			toolBar.add(queryCardAddButton);
//		}
		
		main=new JPanel();
		main_layout=new CardLayout();
		main.setLayout(main_layout);
		this.add(toolBar,BorderLayout.NORTH);
		this.add(main,BorderLayout.CENTER);
	}
	
	//初始化监听器
	private void initListener(){
		
		queryCardButton.addActionListener(this);
//		queryCardAddButton.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		 if(e.getSource()==queryCardButton){
			//会员卡查询按钮
			meberQueryCardPanel=new MemberCoupon();
			main.add(meberQueryCardPanel,"meberQueryCardPanel");
			main_layout.show(main, "meberQueryCardPanel");
			this.setTitle("优惠卷管理--优惠卷查询");
			Util.setButtonStatus(toolBar,queryCardButton);
			SwingUtilities.invokeLater(meberQueryCardPanel);
		}
//		 if(e.getSource()==queryCardAddButton){
//				//添加优惠卷
//				meberAddCardPanel=new MemberCreateCashCardPanel();
//				main.add(meberAddCardPanel,"meberAddCardPanel");
//				main_layout.show(main, "meberAddCardPanel");
//				this.setTitle("添加优惠卷");
//				Util.setButtonStatus(toolBar,queryCardAddButton);
//				//SwingUtilities.invokeLater(meberAddCardPanel);
//			}
		main.updateUI();
	}
	
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type){
		switch(type){
			case 1:{queryCardButton.doClick();break;}
//			case 2:{queryCardAddButton.doClick();break;}
		}
	}
}
